package com.bigplayer.handler;

import com.alibaba.fastjson.JSONObject;
import com.bigplayer.comm.feign.BigPlayerApi;
import com.bigplayer.comm.utils.HttpUtils;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * XxlJob开发示例（Bean模式）
 *
 * 开发步骤：
 * 1、在Spring Bean实例中，开发Job方法，方式格式要求为 "public ReturnT<String> execute(String param)"
 * 2、为Job方法添加注解 "@XxlJob(value="自定义jobhandler名称", init = "JobHandler初始化方法", destroy = "JobHandler销毁方法")"，注解value值对应的是调度中心新建任务的JobHandler属性的值。
 * 3、执行日志：需要通过 "XxlJobLogger.log" 打印执行日志；
 *
 * @author xuxueli 2019-12-11 21:52:51
 */
@Component
public class bigPlayerJob {
    private static Logger logger = LoggerFactory.getLogger(bigPlayerJob.class);

    @Value("${bigPlayUrl}")
    private String bigPlayUrl;
    @Autowired
    private BigPlayerApi bigPlayerApi;
    /**
     * 1、简单任务示例（Bean模式）
     */
    @XxlJob("doubleJobHandler")
    public ReturnT<String> doubleJobHandler(String param) throws Exception {
        XxlJobLogger.log("XXL-JOB, 双色球 参数：{}", param);
//        String s= bigPlayerApi.getDouble(param);
        if(StringUtils.isBlank(param)){
            param="{}";
        }
        String url=bigPlayUrl+"/double/getData";
            String returnStr = HttpUtils.doPost(url, param, null, 3, 10, "utf-8");
            logger.info(returnStr);
        return ReturnT.SUCCESS;
    }

        @XxlJob("threeJobHandler")
        public ReturnT<String> threeJobHandler(String param) throws Exception {
            XxlJobLogger.log("XXL-JOB, getThreeData 参数：{}",param);
//            String s= bigPlayerApi.getThreeData(param);
            if(StringUtils.isBlank(param)){
                param="{}";
            }
            String url =bigPlayUrl+"/double/getThreeData";
            String returnStr = HttpUtils.doPost(url, param, null, 3, 10, "utf-8");
            logger.info(returnStr);
            return ReturnT.SUCCESS;
        }

    }
